{$CLEO .cs}
Alloc($PLAYER_ACTOR, 3)
Alloc($PLAYER_CHAR, 2)

script_name 'GUN'
nop 

:GUN_13
wait 0
if 
  Char.IsInModel($scplayer, 601)   //601 is the vehicle ID
goto_if_false @GUN_13
0@ = Char.StoreCarIsInNoSave($scplayer)
Streaming.RequestModel(1916)
Streaming.RequestModel(1551)
Streaming.LoadAllModelsNow
1@ = Memory.GetVehiclePointer(0@)
1@ += 2380
2@ = Memory.GetVehiclePointer(0@)
2@ += 2384
goto @GUN_95

:GUN_95
wait 0
if and
  Streaming.HasModelLoaded(1916)
  Streaming.HasModelLoaded(1551)
goto_if_false @GUN_95
3@ = Object.Create(1916, 0.0, 0.0, 0.0)
4@ = Object.Create(1551, 0.0, 0.0, 0.0)
Object.SetVisible(4@, False)
Object.SetVisible(3@, True)
Object.SetCollision(3@, False)
Object.SetProofs(3@, True, True, True, True, True)
Object.SetCollision(4@, False)
Object.SetProofs(4@, True, True, True, True, True)
Streaming.MarkModelAsNoLongerNeeded(1916)
Streaming.MarkModelAsNoLongerNeeded(1551)
goto @GUN_241

:GUN_241
wait 0

if or
   not is_char_in_any_car $scplayer
   is_car_dead 0@
then
    goto @GUN_692
end
5@ = Memory.Read(1@, 4, False)
6@ = Memory.Read(2@, 4, False)
5@ *= 180.0
5@ /= 3.141593
6@ *= 180.0
6@ /= 3.141593
Object.AttachToCar(4@, 0@, 0.0, 0.0, 1.49, 0.0, 0.0, 5@) //Object.AttachToCar(4@, 0@, X offset, y offset, z offset, 0.0, 0.0, 5@) //misc_a offset
Object.AttachToObject(3@, 4@, 0.0, 0.0, 0.16, 6@, 0.0, 0.0) //Object.AttachToObject(3@, 4@, 0.0, 0.0, z offset, 6@, 0.0, 0.0) // misc_b offset
Car.SetCanBurstTires(0@, False)
Car.SetProofs(0@, True, False, False, True, True)
Car.SetHealth(0@, 10000)
if 
  Char.IsInAnyCar($scplayer)
goto_if_false @GUN_692
if 
  Pad.IsKeyPressed(KeyCode.RightButton)
goto_if_false @GUN_241
0@ = Char.StoreCarIsInNoSave($scplayer)
7@ = Math.RandomFloatInRange(-1.0, 1.0)
8@ = Math.RandomFloatInRange(-1.0, 1.0)
9@, 10@, 11@ = Object.GetOffsetInWorldCoords(3@, 7@, 500.0, 20.0)
12@, 13@, 14@ = Object.GetCoordinates(3@)
12@, 13@, 14@ = Object.GetOffsetInWorldCoords(3@, 0.0, 1.5, 0.0)
World.FireSingleBullet(12@, 13@, 14@, 9@, 10@, 11@, 100) //100 is gun damage
15@ = Particle.CreateOnObject("GUNFLASH", 3@, 0.0, 2.0, 0.0, True)
Fx.AddSmokeParticle(12@, 13@, 14@, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5, 0.1, 0.125)
Particle.Play(15@)
Particle.PlayAndKill(15@)
Audio.ReportMissionAudioEventAtObject(3@, ScriptSound.SoundMinitankFire)
if 
  Player.IsWantedLevelGreater($PLAYER_CHAR, 0)
then

else
  Player.AlterWantedLevel($PLAYER_CHAR, 1)
end
wait 80
goto @GUN_241


:GUN_692
Object.Delete(3@)
Object.Delete(4@)
Car.MarkAsNoLongerNeeded(0@)
wait 0
goto @GUN_13
